const Service = require('egg').Service;
class HomeService extends Service {
    async newMenu(uid) {
        const sql = `select * from cook LEFT JOIN cook1user ON cook1user.cookid=cook.id LEFT JOIN user ON user.id=cook1user.userid order by RAND() limit 0,15`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async popular(uid) {
        const sql = `select * from cook LEFT JOIN cook1user ON cook1user.cookid=cook.id LEFT JOIN user ON user.id=cook1user.userid order by RAND() limit 0,12`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async popular2(uid) {
        const sql = `select * from cook LEFT JOIN cook1user ON cook1user.cookid=cook.id LEFT JOIN user ON user.id=cook1user.userid order by RAND() limit 0,5`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async popmenu(uid) {
        const sql = `select * from caipu order by RAND() limit 0,4`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async popmenu2(uid) {
        const sql = `select * from cook order by RAND() limit 0,4`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async star(uid) {
        const sql = `select * from user limit 0,7`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async opus(uid) {
        let data = []
        for (let i = 1; i < 8; i++) {
            let sql = `select opusid from opus1user WHERE userid = ` + i
            let data1 = await this.app.mysql.query(sql);
            let data2 = data1.length
            data.push(data2)
        }
        return data;

    }
    async season(uid) {
        const sql = `select * from class`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async zuoping(uid) {
        const sql = `select * from opus order by RAND() limit 6`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async finduser(id) {
        const sql = `select touxiang,username from user WHERE id='${id}'`
        const data = await this.app.mysql.query(sql);
        return data;
    }
}
module.exports = HomeService;